﻿#region License Info
//Component of Cronos Package, http://www.codeplex.com/cronos
//Copyright (C) 2009 Anthony Brockwell

//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either version 2
//of the License, or (at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#endregion


using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using ABMath.ModelFramework.Data;

namespace ABMath.ModelFramework.Visuals
{
    /// <summary>
    /// A visual is an object that is connected to an IUpdateable user control
    /// to be displayed.  Mathematical computations of any sort should be done in the visual.
    /// The visual should be serializable so that it can be saved to a project file.
    /// </summary>
    [Serializable]
    public abstract class Visual : IConnectable
    {
        [NonSerialized]
        private object theObject;
        public object TheObject
        {
            get { return theObject; }
            set { theObject = value;
                OnInputChanged();  }
        }

        [NonSerialized]
        protected IUpdateable associatedControl;
        public IUpdateable AssociatedControl
        { get { return associatedControl; } 
            set { associatedControl = value; } }

        private string toolTipText;
        public string ToolTipText
        {
            get { return toolTipText; }
            set { toolTipText = value; }
        }

        protected virtual bool OnInputChanged()
        {
            return true;
        }

        public int NumInputs()
        {
            return 1;
        }

        public int NumOutputs()
        {
            return 0;
        }

        public virtual List<Type> GetOutputTypesFor(int socket)
        {
            return null;
        }

        public bool InputIsFree(int socket)
        {
            return (theObject == null);
        }

        public bool SetInput(int socket, object item, StringBuilder failMsg)
        {
            if (socket != 0)
                throw new ApplicationException("Error, only 1 socket.");
            theObject = item;
            return OnInputChanged();
        }

        public object GetOutput(int socket)
        {
            throw new ApplicationException("No output for visualizations.");
        }

        public string GetInputName(int index)
        {
            return "Input (MV)TS";
        }

        public string GetOutputName(int index)
        {
            return null;
        }

        public virtual List<Type> GetAllowedInputTypesFor(int socket)
        {
            return new List<Type>();
        }

        public abstract string GetDescription();
        public abstract string GetShortDescription();

        public Color GetBackgroundColor()
        {
            return Color.Gold;
        }

        public Icon GetIcon()
        {
            return null;
        }
    }
}
